package dao;

/**
 *
 * @author yakimovich
 */
import static dao.AbstractJdbcDao.logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author yakimovich
 */
public final class JdbcUtils {
    private JdbcUtils() {
    }

    /**
     * Close a ResultSet.
     * @param rs
     */
    public static void closeQuietly(ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.error(e);
                // NOP
            }
        }
    }

    /**
     * Close a PreparedStatement.
     * @param ps
     */
    public static void closeQuietly(PreparedStatement ps) {
        if (ps != null) {
            try {
                ps.close();
            } catch (SQLException e) {
                logger.error(e);
                // NOP
            }
        }
    }

    /**
     * Close a Connection
     * @param conn
     */
    public static void closeQuietly(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                logger.error(e);
                // NOP
            }
        }
    }

    /**
     * Rollback.
     * @param conn
     */
    public static void rollbackQuietly(Connection conn) {
        if (conn != null) {
            try {
                conn.rollback();
            } catch (SQLException e) {
                logger.error(e);
                // NOP
            }
        }
    }
}
